﻿using Roslyn.Compilers.CSharp;

namespace Runner
{
    internal class SemanticVisitor : SymbolVisitor<object, object>
    {
        // Default VisitSymbol throws NotSupportedException
        protected override object VisitSymbol(Symbol symbol, object argument)
        {
            return null;
        }

        protected override object VisitArrayType(ArrayTypeSymbol symbol, object argument)
        {
            return VisitNamespaceOrType(symbol, argument);
        }

        protected override object VisitDynamicType(DynamicTypeSymbol symbol, object argument)
        {
            return VisitNamespaceOrType(symbol, argument);
        }

        protected override object VisitErrorType(ErrorTypeSymbol symbol, object argument)
        {
            return VisitNamespaceOrType(symbol, argument);
        }

        protected override object VisitNamespace(NamespaceSymbol symbol, object argument)
        {
            return VisitNamespaceOrType(symbol, argument);
        }

        protected override object VisitPointerType(PointerTypeSymbol symbol, object argument)
        {
            return VisitNamespaceOrType(symbol, argument);
        }

        protected override object VisitTypeParameter(TypeParameterSymbol symbol, object argument)
        {
            return VisitNamespaceOrType(symbol, argument);
        }

        // Need this one to loop over the members
        private object VisitNamespaceOrType(NamespaceOrTypeSymbol symbol, object argument)
        {
            foreach (var child in symbol.GetMembers())
            {
                Visit(child, argument);
            }

            return null;
        }

        protected override object VisitNamedType(NamedTypeSymbol symbol, object argument)
        {
//            if (RuleChecker.Rule1034Applies(symbol))
//            {
//                warnings.AddWarning(1034, symbol);
//            }

            return VisitNamespaceOrType(symbol, argument);
        }

        protected override object VisitMethod(MethodSymbol symbol, object argument)
        {
//            if (RuleChecker.Rule1033Applies(symbol))
//            {
//                warnings.AddWarning(1033, symbol);
//            }

            return null;
        }
    }
}
